package com.epalmpay.controller.apimemberapp;


import com.alibaba.fastjson.JSON;
import com.epalmpay.bean.OilcardRechargeInfoBean;
import com.epalmpay.commom.BaseController;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.yunliu.UserAuthMessage;

import com.epalmpay.dto.yunliu.oilcard.CreateOilOrderInDTO;
import com.epalmpay.entity.OrderGood;
import com.epalmpay.entity.TradeOffline;
import com.epalmpay.entity.YsOilcard;
import com.epalmpay.entity.YsOilcardOrder;
import com.epalmpay.service.jobservice.IProfitStatisService;
import com.epalmpay.service.mall.IMallGoodService;
import com.epalmpay.service.member.IMemberService;
import com.epalmpay.service.trade.ITradeService;
import com.epalmpay.service.weixin.ITokenService;
import com.epalmpay.service.weixin.IWxApiFindShopService;
import com.epalmpay.service.weixin.IWxApiMemberService;
import com.epalmpay.service.weixin.IWxApiService;
import com.epalmpay.service.weixin.IWxApiWalletService;
import com.epalmpay.service.yunstream.IAppPayService;
import com.epalmpay.service.yunstream.IOilCardService;
import com.epalmpay.service.yunstream.IOilcardOrderService;
import com.epalmpay.service.yunstream.IYlLoginService;
import com.epalmpay.usercenter.UserAuthApi;
import com.epalmpay.util.*;
import com.epalmpay.util.payplat.UtilFun;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;


/**
 * 
* 类名称：ApiMemberAppYSController.java
* 类描述： 云流 controller
* @author tony
* 创建时间：2017年8月3日
 */
@Controller
@RequestMapping(value="/api/memberapp/ys")
public class ApiMemberAppYSController extends BaseController{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Resource
	private IOilCardService oilCardService;
	
	@Resource
	private IOilcardOrderService oilcardOrderService;
	
	@Resource
	private IWxApiMemberService wxApiMemberService;
	
	@Resource
	private IAppPayService appPayService;
	
	@Resource
	private IYlLoginService ylLoginService;
	@Resource
	private IWxApiService wxApiService;
	@Autowired
    private IMallGoodService mallGoodService;
	@Autowired
	private ITradeService tradeService;

	@Resource
	private IWxApiFindShopService wxApiFindShopService;
	
	@Resource
	private IWxApiWalletService wxApiWalletServiceService;
	
	@Autowired
	private ITokenService tokenService;
	@Autowired
	private FileUpload fileUpload;
	@Resource
	private  IProfitStatisService profitStatisService;
	@Resource
	private IMemberService memberService;
	/**
	 * 签到-开户
	 * @param groupId
	 * @param userId
	 * @param app_member_sid
	 * @return
	 */
	@RequestMapping(value = "/{groupId:[\\w\\W]+}/isLogin", method = {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Response mallIsLogin(@PathVariable String groupId,
										 @RequestParam(required = true) String userId,
										 @RequestParam(required = true) String app_member_sid){

		logBefore(logger, "签到");


		Response message = (Response) new Response().format(false);


		UserAuthMessage userAuthMessage = null;
		try {
			//去云流那边验证用户
			userAuthMessage = UserAuthApi.finishAuthUser(userId, app_member_sid);
		} catch (Exception e) {
			e.printStackTrace();
			return message.format(false, -999, "用户非法，请登录或者注册", null);
		}
		if (userAuthMessage.getErrcode() == 1) {
		} else {
			return message.format(false, -999, "用户非法，请登录或者注册", null);
		}

		try {
			message = ylLoginService.updatecheckMemberInfo(groupId, userAuthMessage);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return message;

	}

	
	/**
	 * 同步头像
	 * 
	 * @param groupId
	 * @return
	 */
	@RequestMapping(value = "/{groupId:[\\w\\W]+}/imgUpdate")
	public @ResponseBody Response mallImgUpdate(@PathVariable String groupId) {
		Response message = (Response) new Response().format(false);
		String userId = this.getRequestParamString("userId", null);
		String appMemberSid = this.getRequestParamString("app_member_sid", null);			
		String sessionKey = UtilFun.passwordMD5(groupId);
		try {
			if(userId==null ||StringUtils.isBlank(appMemberSid)){
				return message.format(false, 0, "参数缺失");
			}
			
			UserAuthMessage wxMessage = UserAuthApi.finishAuthUser(userId, appMemberSid);
			if (wxMessage.getErrcode() == 1) {

				logger.info("wechatCallbackCode......." + sessionKey + "......" + wxMessage.getUserId() + "....." + wxMessage);
				boolean result=ylLoginService.finishUpdateImg(groupId, wxMessage.getUserId(),wxMessage.getImgPath());
				if(result){
					
					return message.format(true, 1, "成功同步头像");
				}else{
					return message.format(false, 0, "操作异常");
				}
				
			} else {
				return message.format(false, -999, "用户非法，请登录或者注册", null);
			}
		} catch (Exception e) {
			e.printStackTrace();
			 return message.format(false, -999, "用户非法，请登录或者注册", null);
		}
		
		
	}



	/**油卡列表
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/oilCardList", method = {RequestMethod.GET,RequestMethod.POST} )
	@ResponseBody
	public Response oilCardList(@RequestParam(required = true) String memberId) throws Exception{
		logBefore(logger, "油卡列表");
		Map<String, Object> map = null;

		try {
			map = oilCardService.getOilCardList(memberId);
			return Response.getSuccess(map);
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			return Response.getError("服务器异常");
		}
	}

	/**
	 * 油卡增加
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/oilCardAdd", method = {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Response oilCardAdd( @RequestParam(required = true) String memberId,
								@RequestParam(required = true) String oilcardNumber,
								@RequestParam(required = true) String oilcardOwen,
								@RequestParam(required = true) String oilcardPhone,
								@RequestParam(required = true) String oilcardType,
								@RequestParam(required = true) Integer isDefault)  {
		logBefore(logger, "油卡增加");
		
		try {
			if(StringUtil.notEmpty(memberId)) {
				oilCardService.addOilCard(memberId,oilcardNumber,oilcardOwen,oilcardPhone,oilcardType,isDefault);
			}
			return Response.getSuccess(null);
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			return Response.getError("服务器异常");
		}
	}

	/**
	 * 油卡删除
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/oilCardDelete", method = {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Response oilCardDelete( @RequestParam(required = true) Long memberId,
								@RequestParam(required = true) Long oilCardId,
								@RequestParam(required = true) String businessCode)  {
		logBefore(logger, "油卡删除");
		
		Response baseResult = new Response();
		try {
			if(memberId==null||oilCardId==null||StringUtil.isEmpty(businessCode)) {
				baseResult.setMessage("设置参数不正确！");
				baseResult.setStatus(false);
				return baseResult;
			}
			
			return	oilCardService.deleteOilCard(memberId,oilCardId,businessCode);
			
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			return Response.getError("服务器异常");
		}
	}

	/**
	 * 油卡更新
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/oilCardUpdate", method = {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Response oilCardUpdate( @RequestParam(required = true) Long memberId,
								   @RequestParam(required = true) Long oilcardId,
								@RequestParam(required = true) String oilcardNumber,
								@RequestParam(required = true) String oilcardOwen,
								@RequestParam(required = true) String oilcardPhone,
								@RequestParam(required = true) String oilcardType,
								@RequestParam(required = true) Integer isDefault)  {
		logBefore(logger, "油卡更新");
		
			String businessCode=getRequestParamString("businessCode", null);
			Response baseResult = new Response();
			try {
				if(memberId==null||oilcardId==null||isDefault==null) {
					baseResult.setMessage("设置参数不正确！");
					baseResult.setStatus(false);
					return baseResult;
				}
				if(StringUtil.isEmpty(oilcardNumber)||StringUtil.isEmpty(businessCode)
						||StringUtil.isEmpty(oilcardOwen)||StringUtil.isEmpty(oilcardPhone)
						||StringUtil.isEmpty(oilcardType)){
					baseResult.setMessage("设置参数不正确！");
					baseResult.setStatus(false);
					return baseResult;
				}
				return oilCardService.updateOilCard(memberId,oilcardId,oilcardNumber,oilcardOwen,oilcardPhone,
					oilcardType,isDefault,businessCode);
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			return Response.getError("服务器异常");
		}
	}
	
	@ResponseBody
	@RequestMapping("setDefault")
	public Response setToDefault(){
		
		Response baseResult = new Response();
		Long memberId=getRequestParamLong("memberId", null);
		String businessCode=getRequestParamString("businessCode", null);
		
		Long id=getRequestParamLong("id", null);
		Integer isdefault=getRequestParamInteger("isdefault", null);
		if(id == null || memberId ==null 
				|| isdefault ==null ||isdefault > 1){
			baseResult.setMessage("设置参数不正确！");
			baseResult.setStatus(false);
			return baseResult;
		}
		
		try {
			int num = oilCardService.updateToDefault(businessCode,memberId,id,isdefault);
			if( num<0 ){
				baseResult.setMessage("设置默认失败，请稍后重试！");
				baseResult.setStatus(false);
				return baseResult;
			}
		} catch (Exception e) {	
			e.printStackTrace();
			baseResult.setMessage("设置默认失败，请稍后重试！");
			baseResult.setStatus(false);
			return baseResult;
		}
		baseResult.setStatus(true);
		baseResult.setMessage("设置成功");
		return baseResult;
	}

	

	/**油卡套餐列表
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("oilCardPackageList")
	public Response selectOilcard(String oilcardType,Long memberId,String userId ,String businessCode){
		Response baseResult = new Response();
		if(StringUtils.isBlank(oilcardType)){
			baseResult.setMessage("请选择油卡类型！");
			baseResult.setStatus(false);
			baseResult.setCode(-5);
			return baseResult;
		}
		
		if(memberId==null||StringUtils.isBlank(userId)){
			baseResult.setMessage("请先进行用户登录！");
			baseResult.setStatus(false);
			baseResult.setCode(-5);
			return baseResult;
		}
		
		//查询所有充值油卡
		List<YsOilcard> oilcards = oilCardService.listOilcard(oilcardType,businessCode);
		int maxAmount=oilcardOrderService.canRechargeAmount(userId,businessCode);
		 //业务需求变更
		int inPackageOrder=oilcardOrderService.inPackageOrder(userId,businessCode);
		Map<String ,Object> result=new HashMap<String ,Object>();
		result.put("oilcards", oilcards);//套餐列表
		result.put("maxAmount", maxAmount);//可优惠金额
		//以前定义的1 表示套餐中不能购买
		result.put("inPackageOrder", inPackageOrder);//是否能购买套餐 ，如果当前无优惠金额时不能购买，有时可以购买
		
		result.put("canBuyPackage",  maxAmount>0?0:1);//是否能购买套餐 ，如果当前无优惠金额时不能购买，有时可以购买
		
		//result.put("inPackageOrder", maxAmount>0?0:1);//是否能购买套餐 ，如果当前无优惠金额时不能购买，有时可以购买
		
		result.put("recharge_date", "1");//可优惠金额
		baseResult.format(true, 1, "成功", result);
		
		return baseResult;
	}

//	/**油卡套餐列表
//	 * @return
//	 * @throws Exception
//	 */
//	@RequestMapping(value = "/oilCardPackageList", method = {RequestMethod.GET,RequestMethod.POST} )
//	@ResponseBody
//	public Response oilCardPackageList(@RequestParam(required = true) String memberId,
//									   @RequestParam(required = true) Integer isStartuse) throws Exception{
//		logBefore(logger, "油卡套餐列表");
//		Map<String, Object> map = null;
//
//		try {
//			map = oilCardService.getOilCardPackageList(memberId,isStartuse);
//			if(map == null || map.size()==0){
//				throw new ApplicationException(Rescode.FAIL,"未查询到记录");
//			}
//			return Response.getSuccess(map);
//		} catch (ApplicationException ae) {
//			logger.error(ae);
//			return Response.getError(ae.errMsg);
//		}
//		catch (Exception e) {
//			logger.error(e);
//			return Response.getError("服务器异常");
//		}
//	}
	
	
	/**
	 * 查看 油卡订单充值详情 
	 * @param orderId
	 * @return
	 */
	@ResponseBody
	@RequestMapping("selectOilcardChargeInfo")
	public Response selectOilcardChargeInfo(Long orderId){
		
		Response baseResult = new Response();
		YsOilcardOrder oilcardOrder=oilcardOrderService.findOilChargeOrderInfo(orderId);
		List<OilcardRechargeInfoBean> oilcardRechargeInfos=oilcardOrderService.findPackageORechargeInfoByOid(orderId);
		
		baseResult.format(true, 1, "成功", oilcardOrder,oilcardRechargeInfos);
		return baseResult;
		
		
	}

	/**
	 * 油卡充值创建订单	
	 * @param oilcardOrder
	 * @return
	 */
	@ResponseBody
	@RequestMapping("createOilcardOrder")
	public Response createOilcardOrder(CreateOilOrderInDTO oilcardOrder){
		Response baseOutDTO = this.checkOilcardOrder(oilcardOrder);
		if(!baseOutDTO.isStatus()){
			logger.info("生成订单失败！传入参数不正确！");
			return 	baseOutDTO;
		}
		Long oilcardId=oilcardOrder.getOilcardId();
		Integer amount=oilcardOrder.getAmount();
		Long memberId =oilcardOrder.getMemberId();
		String businessCode=oilcardOrder.getBusinessCode();
		if(oilcardId==null||amount==null){
			baseOutDTO.setCode(-1);
			baseOutDTO.setMessage("请选择充值套餐！");
			baseOutDTO.setStatus(false);
			logger.info("生成订单没有选择套餐！");
			return 	baseOutDTO;
		}
		
		
		if(memberId==null||StringUtils.isBlank(businessCode)){
			
			baseOutDTO.setCode(-1);
			baseOutDTO.setMessage("参数不对，请更新客户端版本！");
			baseOutDTO.setStatus(false);
			logger.info("生成订单没有选择套餐！");
			return 	baseOutDTO;
		}
		
		//生成订单
		baseOutDTO = oilcardOrderService.insertOilcardOrder(oilcardOrder);
		
		logger.info("生成订单："+oilcardOrder.toString());
		return baseOutDTO;
	}
  /**
   * 油卡订单列表
   * @param memberId
   * @param monthTime
   * @return
   */
	@ResponseBody
	@RequestMapping("selectOrderList")
	public Response  selectOrderList(Long memberId,String monthTime,String businessCode){

		Response baseResult = new Response();
		if(memberId==null||StringUtils.isBlank(monthTime)){
			baseResult.setMessage("查询失败！");
			logger.info("查询订单记录参数异常！");
			baseResult.setStatus(false);
			return baseResult;
		}
		//查询单月记录
		List<YsOilcardOrder> list = oilcardOrderService.selectMonthOrderList(memberId,monthTime);
		logger.info(memberId+"查询"+monthTime+"充值记录！");
		baseResult.setStatus(true);
		baseResult.setData(list);
		return baseResult;
		
	}

	private Response checkOilcardOrder(CreateOilOrderInDTO oilcardOrder){
		Response baseResult = new Response();
		baseResult.setStatus(false);
		
		if(StringUtils.isBlank(oilcardOrder.getOilcardNumber())){
			baseResult.setMessage("油卡号不能为空！");
			return baseResult;
		}
		if(oilcardOrder.getPaymentType() == null){
			baseResult.setMessage("请选择支付类型");
			return baseResult;
		}
		
		if(StringUtils.isBlank(oilcardOrder.getOilcardOwner())){
			baseResult.setMessage("请输入持卡人名称！");
			return baseResult;
		}
		if(StringUtils.isBlank(oilcardOrder.getOilcardPhone())){
			baseResult.setMessage("请输入油卡绑定电话！");
			return baseResult;
		}
		baseResult.setStatus(true);
		baseResult.setMessage("success");
		return baseResult;
	}
	
	
	
	

	@RequestMapping(value = "/oilChargeWxPay")
	public @ResponseBody Response oilCardOrderWxPay( HttpServletRequest request) {
		
		Response baseResult = new Response();
		String groupId =this.getRequestParamString("businessCode", null);// 大商户Code
		Long memberId = this.getRequestParamLong("memberId", null);// 类型
		Long oilcardOrderId = this.getRequestParamLong("orderId", null);// 油卡充值订单ID
		Integer oilcardOrderPrice = this.getRequestParamInteger("price", null);// 支付金额
		if(oilcardOrderPrice==null||memberId==null||oilcardOrderId==null){
			baseResult.setStatus(false);
			baseResult.setMessage("参数不能为空");
			return baseResult;
		}
		if(oilcardOrderPrice.intValue()<=0){
			baseResult.setStatus(false);
			baseResult.setMessage("订单金额不能小于等于0");
			return baseResult;
		}
		String ip = request.getRemoteAddr();
		return oilcardOrderService.oilChargeOrderWeixinPay(oilcardOrderId, oilcardOrderPrice,memberId, groupId, ip);
	}

	@RequestMapping(value = "/oilChargeAliPay")
	public @ResponseBody Response oilCardOrderAliPay( HttpServletRequest request) {
		Response baseResult = new Response();
		String groupId =this.getRequestParamString("businessCode", null);// 大商户Code
		Long memberId = this.getRequestParamLong("memberId", null);// 类型
		Long oilcardOrderId = this.getRequestParamLong("orderId", null);// 油卡充值订单ID
		Integer oilcardOrderPrice = this.getRequestParamInteger("price", null);// 支付金额
		if(oilcardOrderPrice==null||memberId==null||oilcardOrderId==null){
			
			baseResult.setStatus(false);
			baseResult.setMessage("参数不能为空");
			return baseResult;
		}
		if(oilcardOrderPrice.intValue()<=0){
			baseResult.setStatus(false);
			baseResult.setMessage("订单金额不能小于等于0");
			return baseResult;
		}
		String ip = request.getRemoteAddr();
		
		return oilcardOrderService.oilChargeOrderAliPay(oilcardOrderId, oilcardOrderPrice,memberId, groupId, ip);
		
	}
	
	/**
	 * 油卡钱包
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/oilCardChargeOrderPay")
	public @ResponseBody Response oilCardOrderPay() {
         Response baseResult = new Response();
        String groupId =this.getRequestParamString("businessCode", null);// 大商户Code
        Long memberId = this.getRequestParamLong("memberId", null);// 类型
 		Long oilcardOrderId = this.getRequestParamLong("orderId", null);// 油卡充值订单ID
		String payPwd = this.getRequestParamString("payPwd", null);// 支付密码
		Integer goodsOrderPrice = this.getRequestParamInteger("price", null);// 支付金额
		
		if(payPwd == null||oilcardOrderId==null||goodsOrderPrice==null){
			baseResult.setStatus(false);
			baseResult.setMessage("参数不能为空");
			return baseResult;
		}
		if(goodsOrderPrice.intValue()<=0){
			baseResult.setStatus(false);
			baseResult.setMessage("订单金额不能小于等于0");
			return baseResult;
		}
		Response response = null; 
		try {
			response = oilcardOrderService.oilChargeOrderPay(oilcardOrderId, goodsOrderPrice, payPwd,memberId, groupId);
			if(response.isStatus()){
				try {
					wxApiWalletServiceService.finishBuySendMessage(response.getData_extend().toString(),"油卡购买");
				} catch (Exception e) {
					
					e.printStackTrace();
				}
			} 
			return response;
		} catch (ApplicationException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		return response;
		
	}

	/**
	 * 油卡绑定的快捷银行卡 进行充值
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/oilCardOrderbankPay")
	public @ResponseBody Response oilCardOrderbankPay(HttpServletRequest request) {
		 Response baseResult = new Response();
		String groupId=this.getRequestParamString("businessCode", null);// 大商户
		Long memberId = this.getRequestParamLong("memberId", null);// 用户ID
		Long goodsOrderId = this.getRequestParamLong("orderId", null);// 油卡充值订单ID
		/**
		 * 卡号
		 */
		String cardNum = this.getRequestParamString("accNo", null);
		/**
		 * 持卡人姓名
		 */
		String customerName = this.getRequestParamString("accName", null);
		/**
		 * 手机号
		 */
		String mobilePhone = this.getRequestParamString("mobile", null);
		/**
		 * 身份证号
		 */
		String certNo = this.getRequestParamString("certNo", null);
		/**
		 * 银行名
		 */
		String issuerId = this.getRequestParamString("bankName", null);
		/**
		 * 银行卡Id
		 */
		Long cardId = this.getRequestParamLong("cardId", null);

		/**
		 * 银行卡有效期
		 */
		String expdate = this.getRequestParamString("expdate", null);

		/**
		 * 银行卡cvn
		 */
		String cvn = this.getRequestParamString("cvn", null);

		Integer goodsOrderPrice = this.getRequestParamInteger("price", null);// 支付金额

		String bankCodeNew = this.getRequestParamString("bankCodeNew", null);
		
		if(goodsOrderId==null||goodsOrderPrice==null||groupId==null){
			baseResult.setStatus(false);
			baseResult.setMessage("参数不能为空");
			return baseResult;
		}
		if(goodsOrderPrice.intValue()<=0){
			baseResult.setStatus(false);
			baseResult.setMessage("订单金额不能小于等于0");
			return baseResult;
		}
		if (cardId == null) {
			if (cardNum == null || customerName == null || mobilePhone == null || certNo == null || issuerId == null) {
				baseResult.setStatus(false);
				baseResult.setMessage("参数不能为空");
				return baseResult;
			}

			if (!Pattern.matches("^[\u4E00-\u9FFF]+$", customerName)) {
				
				baseResult.setStatus(false);
				baseResult.setMessage("持卡姓名必须为中文");
				return baseResult;
			}
			if(!Tools.checkMobileNumber(mobilePhone)){
				baseResult.setStatus(false);
				baseResult.setMessage("手机号格式");
				return baseResult;
			}
			
			Response response = this.wxApiMemberService.addQuickRechargeMemberCard(groupId, memberId, cardNum, customerName, mobilePhone, certNo, issuerId,
					null, expdate, cvn,bankCodeNew);
			if (response.isStatus()) {
				
				cardId =(Long) response.getData();
			} else {
				return Response.getError("绑卡失败");
			}
				
		}
		String  ip=UtilFun.getIpAddr(request);
		return this.oilcardOrderService.oilChargeOrderBankPay(groupId, memberId, cardId, goodsOrderId, goodsOrderPrice,ip);
		
	}

	/**
	 * 油卡充值，银行卡支付提交
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/oilCardOrderbankPaySubmit")
	public @ResponseBody Response oilCardOrderbankPaysubmit(HttpServletRequest request) {
		 Response baseResult = new Response();
			
		 String groupId=this.getRequestParamString("businessCode", null);// 大商户
		 Long memberId = this.getRequestParamLong("memberId", null);// 类型		
		/**
		 * 订单号
		 */
		String thirdOrderId = this.getRequestParamString("thirdOrderId", null);
		String sysOrderNum = this.getRequestParamString("sysOrderNum", null);
		String paySign = this.getRequestParamString("paySign", null);
		/**
		 * 短信验证码
		 */
		String code = this.getRequestParamString("code", null);
		// 订单记录
		Long orderId = this.getRequestParamLong("orderId", null);
		Long cardId = this.getRequestParamLong("cardId", null);

		if (sysOrderNum == null || code == null || orderId == null || cardId == null) {
			baseResult.setStatus(false);
			baseResult.setMessage("参数不能为空");
			return baseResult;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("thirdOrderId", thirdOrderId);
		params.put("sysOrderNum", sysOrderNum);
		params.put("paySign", paySign);
		params.put("cardId", cardId);
		params.put("code", code);
		String  ip=UtilFun.getIpAddr(request);
		return this.oilcardOrderService.bankPaySubmit(groupId, memberId, orderId, ip,params);
	
	}
	
	
	/**
	 * 订单支付,使用支付宝支付
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/flowsOrderAliPay")
	public @ResponseBody Response flowsOrderAliPay(HttpServletRequest request) {
		
		 Response baseResult = new Response();
		 String groupId=this.getRequestParamString("businessCode", null);// 大商户
         Long memberId = this.getRequestParamLong("memberId", null);// 用户ID
			
		String orderNum = this.getRequestParamString("orderNum", null);
		
		Integer goodsOrderPrice = this.getRequestParamInteger("price", null);
		String notifyUrl= this.getRequestParamString("notifyUrl", null);
		if (orderNum==null||goodsOrderPrice==null||notifyUrl==null||StringUtil.isEmpty(orderNum)||StringUtil.isEmpty(groupId)) {
			baseResult.setStatus(false);
			baseResult.setMessage("参数不能为空");
			return baseResult;
		}
		if(goodsOrderPrice.intValue()<=0){
			baseResult.setStatus(false);
			baseResult.setMessage("订单金额不能小于等于0");
			return baseResult;
		}
		return this.oilcardOrderService.flowsOrderAliPay(orderNum, goodsOrderPrice, memberId, groupId,notifyUrl);
		
	}

	/**
	 * 商城绑定的快捷银行卡 进行充值
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/flowsOrderBankPay")
	public @ResponseBody Response flowsOrderBankPay(HttpServletRequest request) {
		 Response baseResult = new Response();
		 
		 Long memberId = this.getRequestParamLong("memberId", null);// 用户ID
		String orderNum = this.getRequestParamString("orderNum", null);
		 String groupId=this.getRequestParamString("businessCode", null);// 大商户        
		Integer goodsOrderPrice = this.getRequestParamInteger("price", null);
		String notifyUrl= this.getRequestParamString("notifyUrl", null);
		if (orderNum==null||goodsOrderPrice==null||notifyUrl==null) {
			baseResult.setStatus(false);
			baseResult.setMessage("参数不能为空");
			return baseResult;
		}
		if(goodsOrderPrice.intValue()<=0){
			baseResult.setStatus(false);
			baseResult.setMessage("订单金额不能小于等于0");
			return baseResult;
		}
		/**
		 * 卡号
		 */
		String cardNum = this.getRequestParamString("accNo", null);
		/**
		 * 持卡人姓名
		 */
		String customerName = this.getRequestParamString("accName", null);
		/**
		 * 手机号
		 */
		String mobilePhone = this.getRequestParamString("mobile", null);
		/**
		 * 身份证号
		 */
		String certNo = this.getRequestParamString("certNo", null);
		/**
		 * 银行名
		 */
		String issuerId = this.getRequestParamString("bankName", null);
		/**
		 * 银行卡Id
		 */
		Long cardId = this.getRequestParamLong("cardId", null);

		/**
		 * 银行卡有效期
		 */
		String expdate = this.getRequestParamString("expdate", null);

		/**
		 * 银行卡cvn
		 */
		String cvn = this.getRequestParamString("cvn", null);

		/**
		 * 银行代码
		 */

		String bankCodeNew = this.getRequestParamString("bankCodeNew", null);

		if (cardId == null) {
			if (cardNum == null || customerName == null || mobilePhone == null || certNo == null || issuerId == null) {
				baseResult.setStatus(false);
				baseResult.setMessage("参数不能为空");
				return baseResult;
			}

			if (!Pattern.matches("^[\u4E00-\u9FFF]+$", customerName)) {
				baseResult.setStatus(false);
				baseResult.setMessage("持卡姓名必须为中文");
				return baseResult;
			}

			Response response = this.wxApiMemberService.addQuickRechargeMemberCard(groupId, memberId, cardNum, customerName, mobilePhone, certNo, issuerId,
					null, expdate, cvn,bankCodeNew);
			if (response.isStatus()) {			
				
				cardId = (Long)response.getData();
			} else{
				return response;
			}
				
		}
		String ip=UtilFun.getIpAddr(request);
		return this.oilcardOrderService.flowsOrderBankPay(groupId, memberId, cardId, orderNum, goodsOrderPrice,notifyUrl,ip);
		
	}

	/**
	 * 快捷支付提交
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/flowsOrderbankPaySubmit")
	public @ResponseBody Response flowsOrderbankPaySubmit(HttpServletRequest request) {
		Response baseResult = new Response();
		  Long memberId = this.getRequestParamLong("memberId", null);// 用户ID
		/**
		 * 订单号
		 */
		  String groupId=this.getRequestParamString("businessCode", null);// 大商户
	       
		String thirdOrderId = this.getRequestParamString("thirdOrderId", null);
		String sysOrderNum = this.getRequestParamString("sysOrderNum", null);
		String paySign = this.getRequestParamString("paySign", null);
		/**
		 * 短信验证码
		 */
		String code = this.getRequestParamString("code", null);
		// 订单记录
		Long orderId = this.getRequestParamLong("orderId", null);
		Long cardId = this.getRequestParamLong("cardId", null);

		if (sysOrderNum == null || code == null || orderId == null || cardId == null) {
			baseResult.setStatus(false);
			baseResult.setMessage("参数不能为空");
			return baseResult;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("thirdOrderId", thirdOrderId);
		params.put("sysOrderNum", sysOrderNum);
		params.put("paySign", paySign);
		params.put("cardId", cardId);
		params.put("code", code);
		String ip=UtilFun.getIpAddr(request);
		return  this.oilcardOrderService.bankPaySubmit(groupId, memberId, orderId,ip, params);
		
	}

	/**
	 * 流量卡充值，订单支付
	 * @return
	 */
	@RequestMapping(value = "flowsOrderPay")
	public @ResponseBody Response flowsOrderPay() throws Exception {
		Response baseResult = new Response();
		Long memberId = this.getRequestParamLong("memberId", null);// 用户ID
		 String groupId=this.getRequestParamString("businessCode", null);// 大商户      
		String payPwd = this.getRequestParamString("payPwd", null);
		String orderNum= this.getRequestParamString("orderNum", null);
		Integer goodsOrderPrice = this.getRequestParamInteger("price", null);
		String notifyUrl= this.getRequestParamString("notifyUrl", null);
		if (StringUtil.isEmpty(groupId)||memberId==null||payPwd == null||orderNum==null||goodsOrderPrice==null||notifyUrl==null) {
			baseResult.setStatus(false);
			baseResult.setMessage("参数不能为空");
			return baseResult;
		}
		if(goodsOrderPrice.intValue()<=0){
			baseResult.setStatus(false);
			baseResult.setMessage("订单金额不能小于等于0");
			return baseResult;
		}
		Response response=  this.oilcardOrderService.flowsOrderPay(orderNum,notifyUrl, goodsOrderPrice, payPwd, memberId, groupId);
		if(response.isStatus()){
			try {
				wxApiWalletServiceService.finishBuySendMessage(response.getData_extend().toString(),"流量购买");
			} catch (Exception e) {
				
				e.printStackTrace();
			}
		}
	   return response;
	}

	/**
	 * 流量卡充值,使用微信支付
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/flowsOrderWxPay")
	public @ResponseBody Response flowsOrderWxPay( HttpServletRequest request) {
		Response baseResult = new Response();
		 String groupId=this.getRequestParamString("businessCode", null);// 大商户      
		Long memberId = this.getRequestParamLong("memberId", null);// 用户ID
		String orderNum = this.getRequestParamString("orderNum", null);
		Integer goodsOrderPrice = this.getRequestParamInteger("price", null);
		String notifyUrl= this.getRequestParamString("notifyUrl", null);
		if (orderNum==null||goodsOrderPrice==null||notifyUrl==null) {
			baseResult.setStatus(false);
			baseResult.setMessage("参数不能为空");
			return baseResult;
		}
		if(goodsOrderPrice.intValue()<=0){
			baseResult.setStatus(false);
			baseResult.setMessage("订单金额不能小于等于0");
			return baseResult;
		}
		String ip = request.getRemoteAddr();
		return this.oilcardOrderService.flowsOrderWxPay(orderNum, goodsOrderPrice,memberId, groupId, ip,notifyUrl);
	}

	
	/**获取钱包二维码信息
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getpaycrcode", method = {RequestMethod.GET,RequestMethod.POST} )
	@ResponseBody
	public Response getpaycrcode(String memberId,String token) throws Exception{
		logBefore(logger, "用户钱包二维码获取");
		
		HashMap<String, String> resultMap = new HashMap<String, String>();
		resultMap.put("会员编号", memberId);
		String nullParam=Response.checkNull(resultMap);
		if (null != nullParam) {
			return Response.getError(nullParam+"不能为空");
		}
		try {
			Map<String, Object> map=wxApiService.queryPaycrcode(memberId,HOME_URL+"/EBosService/api/wallet/paycrcodeCallback");//回调url 待测试
			if(map == null){
				return Response.getError("二维码生成失败");
			}else{
				return Response.getSuccessExtend(map.get("qrcode"),map.get("marked"));
			} 
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			return Response.getError("服务器异常");
		}
	}
	
	
	/**
	 * 查询会员银行卡列表 
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/bankcardlist",  method = {RequestMethod.GET,RequestMethod.POST} )
	@ResponseBody
	public Response bankList(String memberId,String token) throws Exception {
		logBefore(logger, "查询会员银行列表");
		HashMap<String, String> resultMap = new HashMap<String, String>();
		resultMap.put("会员编号", memberId);
		String nullParam=Response.checkNull(resultMap);
		if (null != nullParam) {
			return Response.getError(nullParam+"不能为空");
		}
		try { 
			Response map = wxApiMemberService.bankListSort(memberId);
			return map;
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			return Response.getError("服务器异常");
		}
	}
	
	/**
	 * 确认转账
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/usertransfer", method = {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Response usertransfer( String memberId,
								 String toPhone,
								 String amount,String password,String toMemberId) throws Exception {
		logBefore(logger, "确认转账");
		HashMap<String, String> resultMap = new HashMap<String, String>();
		resultMap.put("会员编号", memberId);
		resultMap.put("转账金额", amount);
		resultMap.put("支付密码", password);
		String nullParam=Response.checkNull(resultMap);
		if (null != nullParam) {
			return Response.getError(nullParam+"不能为空");
		}
		if(Tools.isEmpty(toPhone)&&Tools.isEmpty(toMemberId)){
			return Response.getError("手机号或会员号不能同时为空");
		}
//		Boolean flag=tokenService.checkToken(memberId,token);
//		if(flag){ 
//			return Response.getError("token错误");
//		}
		try {
		    Map<String, Object> map=appPayService.insertUserTransfer(memberId,toPhone,toMemberId,amount,password);
		    try {
		    	 wxApiWalletServiceService.updatefinishSendMessage(map.get("transferOrderNum").toString(), UserAuthApi.MC_BLANCE_CHANGE);
		    	 wxApiWalletServiceService.updatefinishSendMessage(map.get("transferOrderNum").toString(), UserAuthApi.MC_TRANSFER);
			} catch (Exception e) {
				logBefore(logger, "转账消息发送失败");
			}
			return Response.getSuccess(map);
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			return Response.getError("服务器异常");
		}
	}

	
	/**
	 * 转账记录
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/transferAnnal", method = {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Response TransferAnnal( String memberId,String token) throws Exception {
		logBefore(logger, "确认转账");
		HashMap<String, String> resultMap = new HashMap<String, String>();
		resultMap.put("会员编号", memberId);
		String nullParam=Response.checkNull(resultMap);
		if (null != nullParam) {
			return Response.getError(nullParam+"不能为空");
		}
//		Boolean flag=tokenService.checkToken(memberId,token);
//		if(flag){ 
//			return Response.getError("token错误");
//		}
		try {
			return appPayService.selectTransferAnnal(memberId);
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			return Response.getError("服务器异常");
		}
	}

	
		/**
		 * 用户外部微信进行钱包充值
		 *
		 * @return 
		 * @throws Exception
		 */
		@RequestMapping(value = "/unifiedorder",  method = {RequestMethod.GET,RequestMethod.POST} )
		@ResponseBody
		public Response unifiedorder(HttpServletRequest request,String memberId,Integer goodsOrderPrice,String token) throws Exception {
			logBefore(logger, "用户外部微信进行钱包充值"+HOME_URL);
			HashMap<String, String> resultMap = new HashMap<String, String>();
			resultMap.put("会员编号", memberId);
			resultMap.put("订单金额", goodsOrderPrice+"");
			String nullParam=Response.checkNull(resultMap);
			if (null != nullParam) {
				return Response.getError(nullParam+"不能为空");
			}
//			Boolean flag=tokenService.checkToken(memberId,token);
//			if(!flag){ 
//				return Response.getError("token错误");
//			}
			try { 
				Response map = appPayService.updateWeiXinPay(memberId, goodsOrderPrice, Tools.getIpAddr(request),HOME_URL);
				return map;
			} catch (ApplicationException ae) {
				logger.error(ae);
				return Response.getError(ae.errMsg);
			}
			catch (Exception e) {
				logger.error(e);
				return Response.getError("服务器异常");
			}
		}
		
		
		/**
		 * 用户外部支付宝进行钱包充值
		 *
		 * @return 
		 * @throws Exception
		 */
		@RequestMapping(value = "/aliChargeOrder",  method = {RequestMethod.GET,RequestMethod.POST} )
		@ResponseBody
		public Response aliChargeOrder(HttpServletRequest request,String memberId,Integer goodsOrderPrice,String token) throws Exception {
			logBefore(logger, "用户外部支付宝进行钱包充值");
			HashMap<String, String> resultMap = new HashMap<String, String>();
			resultMap.put("会员编号", memberId);
			resultMap.put("订单金额", goodsOrderPrice+"");
			String nullParam=Response.checkNull(resultMap);
			if (null != nullParam) {
				return Response.getError(nullParam+"不能为空");
			}
//			Boolean flag=tokenService.checkToken(memberId,token);
//			if(!flag){ 
//				return Response.getError("token错误");
//			}
			try { 
				Response map = appPayService.updateAliPay(memberId, goodsOrderPrice);
				return map;
			} catch (ApplicationException ae) {
				logger.error(ae);
				return Response.getError(ae.errMsg);
			}
			catch (Exception e) {
				logger.error(e);
				return Response.getError("服务器异常");
			}
		}


	/**
	 * 银行卡快捷支付充值认证   修改为 提现卡升级为快捷卡
	 * @param request
	 * @param memberId
	 * @param tranAmt
	 * @param bankCode
	 * @param accNo
	 * @param accName
	 * @param certNo
	 * @param mobile
	 * @param cardCvn
	 * @param cardExpdate
	 * @param token
	 * @return
	 * @throws Exception
	 */

		@RequestMapping(value = "/bankcardverify", method = {RequestMethod.GET,RequestMethod.POST})
		@ResponseBody
		public Response bankcardverify(HttpServletRequest request,String memberId,String tranAmt, String bankCode,String accNo,
	    		  String accName,String certNo,String mobile,String cardCvn,String cardExpdate,String token) throws Exception {
			logBefore(logger, "银行卡快捷支付认证");
			HashMap<String, String> resultMap = new HashMap<String, String>();
			resultMap.put("会员编号", memberId);
			resultMap.put("交易金额", tranAmt);
			resultMap.put("银行行号 ", bankCode);
			resultMap.put("银行卡号", accNo);
			resultMap.put("持卡人姓名", accName);
			resultMap.put("身份证号码", certNo);
			resultMap.put("银行预留手机号", mobile);
			String nullParam=Response.checkNull(resultMap);
			if (null != nullParam) {
				return Response.getError(nullParam+"不能为空");
			}
			if(!Tools.checkMobileNumber(mobile)){
				return Response.getError("手机号码格式不对");
			}
//			Boolean flag=tokenService.checkToken(memberId,token);
//			if(flag){ 
//				return Response.getError("token错误");
//			}
			try {
				Map<String, Object> result=appPayService.insertBankCardVefity(memberId, tranAmt, bankCode, accNo, accName, certNo, mobile, cardCvn, cardExpdate, Tools.getIpAddr(request));
				return Response.getSuccess(result);
			} catch (ApplicationException ae) {
				logger.error(ae);
				return Response.getError(ae.errMsg);
			}
			catch (Exception e) {
				logger.error(e);
				return Response.getError("服务器异常");
			}
		}
			
		
		
		/**
		 * 绑卡快捷支付充值(消费)认证 提交支付
		 *
		 * @return
		 * @throws Exception
		 */
		@RequestMapping(value = "/bankcardverifysubmit", method = {RequestMethod.GET,RequestMethod.POST})
		@ResponseBody
		public Response bankcardverifysubmit(HttpServletRequest request,String memberId, String code,String token) throws Exception {
			logBefore(logger, "绑卡快捷支付充值(消费)认证 提交支付");
			HashMap<String, String> resultMap = new HashMap<String, String>();
			resultMap.put("会员编号", memberId);
			resultMap.put("验证码", code);
			String nullParam=Response.checkNull(resultMap);
			if (null != nullParam) {
				return Response.getError(nullParam+"不能为空");
			}
//			Boolean flag=tokenService.checkToken(memberId,token);
//			if(flag){ 
//				return Response.getError("token错误");
//			}
			try {
				Map<String, Object> result=appPayService.updatebankcardsubmit(memberId,code,Tools.getIpAddr(request));
				return Response.getSuccess(result);
			} catch (ApplicationException ae) {
				logger.error(ae);
				return Response.getError(ae.errMsg);
			}
			catch (Exception e) {
				logger.error(e);
				return Response.getError("服务器异常");
			}
		}
		
		
		/**
		 * 已存在银行卡快捷支付充值认证
		 *
		 * @return
		 * @throws Exception
		 */
		@RequestMapping(value = "/existCardsubmit", method = {RequestMethod.GET,RequestMethod.POST})
		@ResponseBody
		public Response existCardsubmit(HttpServletRequest request,String memberId,String cardId,String tranAmt) throws Exception {
			logBefore(logger, "已存在银行卡快捷支付充值认证");
			HashMap<String, String> resultMap = new HashMap<String, String>();
			resultMap.put("会员编号", memberId);
			resultMap.put("银行卡编号", cardId);
			resultMap.put("交易金额", tranAmt);
			String nullParam=Response.checkNull(resultMap);
			if (null != nullParam) {
				return Response.getError(nullParam+"不能为空");
			}
//			Boolean flag=tokenService.checkToken(memberId,token);
//			if(flag){ 
//				return Response.getError("token错误");
//			}
			try {
				Map<String, Object> result=appPayService.updateExistCardsubmit(memberId,Tools.getIpAddr(request),cardId,tranAmt);
				return Response.getSuccess(result);
			} catch (ApplicationException ae) {
				logger.error(ae);
				return Response.getError(ae.errMsg);
			}
			catch (Exception e) {
				logger.error(e);
				return Response.getError("服务器异常");
			}
		}
		
		
		/**
		 * 用户外部微信进行购买-商品支付
		 *
		 * @return 
		 * @throws Exception
		 */
		@RequestMapping(value = "/goodsOrderWxPay",  method = {RequestMethod.GET,RequestMethod.POST} )
		@ResponseBody
		public Response goodsOrderWxPay(HttpServletRequest request,String memberId,String orderId,Integer price,String token) throws Exception {
			logBefore(logger, "用户外部微信进行-商品支付"+HOME_URL);
			HashMap<String, String> resultMap = new HashMap<String, String>();
			resultMap.put("会员编号", memberId);
			resultMap.put("订单编号", orderId);
			resultMap.put("订单金额", price+"");
			String nullParam=Response.checkNull(resultMap);
			if (null != nullParam) {
				return Response.getError(nullParam+"不能为空");
			}
//			Boolean flag=tokenService.checkToken(memberId,token);
//			if(!flag){ 
//				return Response.getError("token错误");
//			}
			try { 
				Response map = appPayService.updateWeiXinGoodsPay(memberId, price,orderId, Tools.getIpAddr(request),HOME_URL);
				return map;
			} catch (ApplicationException ae) {
				logger.error(ae);
				return Response.getError(ae.errMsg);
			}
			catch (Exception e) {
				logger.error(e);
				return Response.getError("服务器异常");
			}
		}
		
		/**
		 * 用户外部支付宝进行-商品支付
		 *
		 * @return 
		 * @throws Exception
		 */
		@RequestMapping(value = "/goodsOrderAliPay",  method = {RequestMethod.GET,RequestMethod.POST} )
		@ResponseBody
		public Response goodsOrderAliPay(HttpServletRequest request,String memberId,String orderId,Integer price,String token) throws Exception {
			logBefore(logger, "用户外部支付宝进行-商品支付");
			HashMap<String, String> resultMap = new HashMap<String, String>();
			resultMap.put("会员编号", memberId);
			resultMap.put("订单编号", orderId);
			resultMap.put("订单金额", price+"");
			String nullParam=Response.checkNull(resultMap);
			if (null != nullParam) {
				return Response.getError(nullParam+"不能为空");
			}
//			Boolean flag=tokenService.checkToken(memberId,token);
//			if(!flag){ 
//				return Response.getError("token错误");
//			}
			try { 
				Response map = appPayService.updateAliGoodsPay(memberId, price, orderId);
				return map;
			} catch (ApplicationException ae) {
				logger.error(ae);
				return Response.getError(ae.errMsg);
			}
			catch (Exception e) {
				logger.error(e);
				return Response.getError("服务器异常");
			}
		}
		
		/**
		 * 用户钱包 购买 支付完成提交
		 *
		 * @return 
		 * @throws Exception
		 */
		@RequestMapping(value = "/goodsOrderPay",  method = {RequestMethod.GET,RequestMethod.POST} )
		@ResponseBody
		public Response goodsOrderPay(HttpServletRequest request,String memberId,String orderId,Integer price,
				String payPwd,String token) throws Exception {
			logBefore(logger, "用户外部支付宝进行-商品支付");
			HashMap<String, String> resultMap = new HashMap<String, String>();
			resultMap.put("会员编号", memberId);
			resultMap.put("订单编号", orderId);
			resultMap.put("订单金额", price+"");
			String nullParam=Response.checkNull(resultMap);
			if (null != nullParam) {
				return Response.getError(nullParam+"不能为空");
			}
//			Boolean flag=tokenService.checkToken(memberId,token);
//			if(!flag){ 
//				return Response.getError("token错误");
//			}
			try { 
				Response map = appPayService.updateGoodsOrderPay(memberId, orderId, payPwd, price);
				try {
					if(map.isStatus()){
						wxApiWalletServiceService.finishBuySendMessage(map.getData_extend().toString(),"商品购买");
					}
				} catch (Exception e) {
					e.printStackTrace();
					logBefore(logger, "通知发送异常");
				}
				return map;
			} catch (ApplicationException ae) {
				logger.error(ae);
				return Response.getError(ae.errMsg);
			}
			catch (Exception e) {
				logger.error(e);
				return Response.getError("服务器异常");
			}
		}
		
		
		/**
		 * 银行卡 首次绑卡购买商品
		 */
		@RequestMapping(value = "/bankGoodsPay", method = {RequestMethod.GET,RequestMethod.POST})
		@ResponseBody
		public Response bankGoodsPay(HttpServletRequest request,String memberId,String tranAmt, String bankCode,String accNo,
	    		  String accName,String certNo,String mobile,String cardCvn,String cardExpdate,String token,String orderId) throws Exception {
			logBefore(logger, "银行卡 首次绑卡购买商品认证");
			HashMap<String, String> resultMap = new HashMap<String, String>();
			resultMap.put("会员编号", memberId);
			resultMap.put("交易金额", tranAmt);
			resultMap.put("银行行号 ", bankCode);
			resultMap.put("银行卡号", accNo);
			resultMap.put("持卡人姓名", accName);
			resultMap.put("身份证号码", certNo);
			resultMap.put("银行预留手机号", mobile);
			resultMap.put("支付订单号", orderId);
			String nullParam=Response.checkNull(resultMap);
			if (null != nullParam) {
				return Response.getError(nullParam+"不能为空");
			}
			if(!Tools.checkMobileNumber(mobile)){
				return Response.getError("手机号码格式不对");
			}
//			Boolean flag=tokenService.checkToken(memberId,token);
//			if(flag){ 
//				return Response.getError("token错误");
//			}
			try {
				Map<String, Object> result=appPayService.insertbankGoodsPay(memberId, tranAmt, bankCode, accNo, accName, certNo, mobile, cardCvn, cardExpdate, Tools.getIpAddr(request),orderId);
				return Response.getSuccess(result);
			} catch (ApplicationException ae) {
				logger.error(ae);
				return Response.getError(ae.errMsg);
			}
			catch (Exception e) {
				logger.error(e);
				return Response.getError("服务器异常");
			}
		}
			
		
		/**
		 * 已存在银行卡快捷支付 购买商品
		 *
		 * @return
		 * @throws Exception
		 */
		@RequestMapping(value = "/existBankGoodsPay", method = {RequestMethod.GET,RequestMethod.POST})
		@ResponseBody
		public Response existBankGoodsPay(HttpServletRequest request,String memberId,String cardId,String tranAmt,String orderId) throws Exception {
			logBefore(logger, "已存在银行卡快捷支付充值认证");
			HashMap<String, String> resultMap = new HashMap<String, String>();
			resultMap.put("会员编号", memberId);
			resultMap.put("银行卡编号", cardId);
			resultMap.put("交易金额", tranAmt);
			resultMap.put("支付订单号", orderId);
			String nullParam=Response.checkNull(resultMap);
			if (null != nullParam) {
				return Response.getError(nullParam+"不能为空");
			}
//			Boolean flag=tokenService.checkToken(memberId,token);
//			if(flag){ 
//				return Response.getError("token错误");
//			}
			try {
				Map<String, Object> result=appPayService.updateExistBankGoodsPay(memberId,Tools.getIpAddr(request),cardId,tranAmt,orderId);
				return Response.getSuccess(result);
			} catch (ApplicationException ae) {
				logger.error(ae);
				return Response.getError(ae.errMsg);
			}
			catch (Exception e) {
				logger.error(e);
				return Response.getError("服务器异常");
			}
		}
		
		
		/**
		 * 用户申请提现-信用卡还款 
		 * @return 
		 * @throws Exception
		 */
		@RequestMapping(value = "/bankWithdrawal",  method = {RequestMethod.GET,RequestMethod.POST} )
		@ResponseBody
		public Response bankWithdrawal(HttpServletRequest request,String memberId,Integer tranAmt,String cardId,
				String payPwd,String token) throws Exception {
			logBefore(logger, "用户申请提现-信用卡还款");
			HashMap<String, String> resultMap = new HashMap<String, String>();
			resultMap.put("会员编号", memberId);
			resultMap.put("银行卡编号", cardId);
			resultMap.put("提现金额", tranAmt+"");
			String nullParam=Response.checkNull(resultMap);
			if (null != nullParam) {
				return Response.getError(nullParam+"不能为空");
			}
			if (tranAmt<=200) {
				return Response.getError("提现金额不低于2元");
			}
//			Boolean flag=tokenService.checkToken(memberId,token);
//			if(!flag){    
//				return Response.getError("token错误");   
//			}
			Map<String, Object> mapFee=wxApiMemberService.selectFee(memberId, tranAmt,"4007");
			if(mapFee == null || mapFee.size()==0){
				throw new ApplicationException(Rescode.FAIL,"未查询到记录");
			}
			logBefore(logger, "计算手续费map"+mapFee);
			String fee=mapFee.get("fee").toString();
			try { 
				//因提现回调通知可能早于返回结果通过 所有处理结果2步操作
				HashMap<String, Object> hashmap = appPayService.updateApplyWithdraw(memberId, tranAmt, cardId, payPwd,Integer.valueOf(fee)); 
				if(hashmap!=null){
					Response map = appPayService.sendApplyWithdraw(hashmap, tranAmt, payPwd,Integer.valueOf(fee));
					logBefore(logger, "用户申请提现-信用卡还款申请成功--------------------------------------------------------");
					return map;
				}else{
					return Response.getError("服务器异常");
				}
			} catch (ApplicationException ae) {
				logger.error(ae);
				return Response.getError(ae.errMsg);
			}
			catch (Exception e) {
				logger.error(e);
				return Response.getError("服务器异常");
			}
		}
		
		
		/**
		 * 实名认证
		 *
		 * @return
		 * @throws Exception
		 */
		@RequestMapping(value = "/verified", method = {RequestMethod.GET,RequestMethod.POST})
		@ResponseBody
		public Response Verified( String memberId, String idNo, String name) throws Exception {
			logBefore(logger, "实名认证");
			HashMap<String, String> resultMap = new HashMap<String, String>();
			resultMap.put("会员编号", memberId);
			resultMap.put("身份证号", idNo);
			resultMap.put("姓名", name);
			String nullParam=Response.checkNull(resultMap);
			if (null != nullParam) {
				return Response.getError(nullParam+"不能为空");
			}
			Map<String, Object> map = new HashMap<String, Object>();
			try {
				Boolean flag=appPayService.updateVerified(memberId, idNo, name);
				if(flag){
					return Response.getSuccess(map);
				}else{
					return Response.getError("服务器异常");
				}
			} catch (ApplicationException ae) {
				logger.error(ae);
				return Response.getError(ae.getErrMsg());
			}
			catch (Exception e) {
				logger.error(e);
				return Response.getError("服务器异常");
			}
		}
		
		
		/**
		 * 认证并重置支付密码
		 *
		 * @return
		 * @throws Exception
		 */
		@RequestMapping(value = "/verifiedPassword", method = {RequestMethod.GET,RequestMethod.POST})
		@ResponseBody
		public Response VerifiedPassword( String memberId, String idNo, String name,
									  String password) throws Exception {
			logBefore(logger, "认证并重置支付密码");
			HashMap<String, String> resultMap = new HashMap<String, String>();
			resultMap.put("会员编号", memberId);
			resultMap.put("身份证号", idNo);
			resultMap.put("姓名", name);
			resultMap.put("支付密码", password);
			String nullParam=Response.checkNull(resultMap);
			if (null != nullParam) {
				return Response.getError(nullParam+"不能为空");
			}
			Map<String, Object> map = new HashMap<String, Object>();
			try {
				Boolean flag=appPayService.updateVerifiedPassword(memberId, idNo, name,password);
				if(flag){
					return Response.getSuccess(map);
				}else{
					return Response.getError("服务器异常");
				}
			} catch (ApplicationException ae) {
				logger.error(ae);
				return Response.getError(ae.getErrMsg());
			}
			catch (Exception e) {
				logger.error(e);
				return Response.getError("服务器异常");
			}
		}

	/**
	 * 车门店列表
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/carShopList", method = {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Response carShopList(@RequestParam(required = true) String groupId,
								@RequestParam(required = true) String memberId,
								@RequestParam(required = false) String user_longitude,
								@RequestParam(required = false) String user_latitude,
								@RequestParam(required = false) String address_province,
								@RequestParam(required = false) Integer distance,
								@RequestParam(required = false) String name,
								@RequestParam(required = false) Integer goodCategory,
								@RequestParam(required =false) Integer YsServiceType,
								@RequestParam(required =false) Integer YsOrderBy,
								@RequestParam(required = true) Integer pageNo,
								@RequestParam(required = true) Integer pageSize,
								@RequestParam(required =false) String province,
								@RequestParam(required = false) String city,
								@RequestParam(required = false) String district
								) throws Exception {
		logBefore(logger, "车门店列表");
		Map<String, Object> map = null;

		try {
			map = wxApiFindShopService.findDiscountCarShopList2(groupId,memberId,user_longitude,user_latitude,address_province,
					distance,name,goodCategory,YsServiceType,YsOrderBy,pageNo,pageSize,province,city,district);
			if(map == null || map.size()==0){
				throw new ApplicationException(Rescode.FAIL,"未查询到记录");
			}
			logger.debug(JSON.toJSONString(map));
			return Response.getSuccess(map);
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			return Response.getError("服务器异常");
		}
	}

	/**
	 * 车门店地图列表
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/carShopMapList", method = {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Response carShopMapList(@RequestParam(required = true) String groupId,
								@RequestParam(required = true) String memberId,
								@RequestParam(required = true) String user_longitude,
								@RequestParam(required = true) String user_latitude,
								@RequestParam(required = true) Integer distance) throws Exception {
		logBefore(logger, "车门店列表");
		Map<String, Object> map = null;
		try {
			map = wxApiFindShopService.findDiscountCarShopMapList(groupId,memberId,user_longitude,user_latitude,distance);
			if(map == null || map.size()==0){
				throw new ApplicationException(Rescode.FAIL,"未查询到记录");
			}
			logger.debug(JSON.toJSONString(map));
			return Response.getSuccess(map);
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			return Response.getError("服务器异常");
		}
	}

	/**
	 * 车门店详情
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/carshopdiscountdetail", method ={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Response carshopdiscountdetail(@RequestParam(required = true) String groupId,
									   @RequestParam(required = true) String memberId,
									   @RequestParam(required = false) String user_longitude,
									   @RequestParam(required = false) String user_latitude,
									   @RequestParam(required = true) String shop_id) throws Exception {
		logBefore(logger, "门店详情");
		Map<String, Object> map = null;

		try {
			map = wxApiFindShopService.getCarShopDiscountDetail(groupId,memberId,user_longitude,user_latitude,shop_id);
			if(map == null || map.size()==0){
				throw new ApplicationException(Rescode.FAIL,"未查询到记录");
			}
			logger.debug(JSON.toJSONString(map));
			return Response.getSuccess(map);
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			return Response.getError("服务器异常");
		}
	}

	/**
	 * 门店介绍
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/carShopDetail", method ={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Response carShopDetail(@RequestParam(required = true) String groupId,
										  @RequestParam(required = true) String memberId,
										  @RequestParam(required = false) String user_longitude,
										  @RequestParam(required = false) String user_latitude,
										  @RequestParam(required = true) String shop_id) throws Exception {
		logBefore(logger, "门店介绍 ");
		Map<String, Object> map = null;

		try {
			map = wxApiFindShopService.carShopDetail(groupId,memberId,user_longitude,user_latitude,shop_id);
			if(map == null || map.size()==0){
				throw new ApplicationException(Rescode.FAIL,"未查询到记录");
			}
			return Response.getSuccess(map);
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			return Response.getError("服务器异常");
		}
	}



	/**
	 * 热门城市
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/cityList", method ={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Response cityList(@RequestParam(required = true) String groupId,
								  @RequestParam(required = true) String memberId
								  ) throws Exception {
		logBefore(logger, "门店介绍 ");
		Map<String, Object> map = null;

		try {
			map = wxApiFindShopService.cityList(groupId,memberId);
			if(map == null || map.size()==0){
				throw new ApplicationException(Rescode.FAIL,"未查询到记录");
			}
			return Response.getSuccess(map);
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			return Response.getError("服务器异常");
		}
	}

	/**
	 * 全部点评
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/allComment", method ={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Response allComment(@RequestParam(required = true) String groupId,
							   @RequestParam(required = true) String memberId,
							   @RequestParam(required = true) String shopId,
							   @RequestParam(required = false) String score,
							   @RequestParam(required = true) Integer pageNo,
							   @RequestParam(required = true) Integer pageSize
							   ) throws Exception {
		logBefore(logger, "门店介绍 ");
		Map<String, Object> map = null;

		try {
			map = wxApiFindShopService.allCommentList(groupId,memberId,shopId,score,pageNo,pageSize);
			if(map == null || map.size()==0){
				throw new ApplicationException(Rescode.FAIL,"未查询到记录");
			}
			return Response.getSuccess(map);
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			return Response.getError("服务器异常");
		}
	}


	/**
	 * 交易记录列表
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getOrdersNew", method = {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Response carShopList(@RequestParam(required = true) String memberId,
								@RequestParam(required = true) String datefrom,
								@RequestParam(required = true) String dateto,
								@RequestParam(required = false) String type,
								@RequestParam(required = false) String memo,
								@RequestParam(required = false) Integer app_type,
								@RequestParam(required = true) Integer pageNo,
								@RequestParam(required = true) Integer pageSize) throws Exception {
		logBefore(logger, "交易记录");
		Map<String, Object> map = null;

		try {
			map = wxApiFindShopService.findAllTrandList(memberId,datefrom,dateto,type,memo,app_type,pageNo,pageSize);
			if(map == null || map.size()==0){
				throw new ApplicationException(Rescode.FAIL,"未查询到记录");
			}
			return Response.getSuccess(map);
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			return Response.getError("服务器异常");
		}
	}



	/**
	 * 交易数据详情
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getOrderDetail", method ={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Response getOrderDetail(@RequestParam(required = true) String memberId,
										  @RequestParam(required = true) String orderId) throws Exception {
		logBefore(logger, "门店详情");
		Map<String, Object> map = null;
		try {
			map = wxApiFindShopService.getOrderDetail(memberId,orderId);
			if(map == null || map.size()==0){
				throw new ApplicationException(Rescode.FAIL,"未查询到记录");
			}
			return Response.getSuccess(map);
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			return Response.getError("服务器异常");
		}
	}



	/**
	 * 交易数据详情
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getTransOrderDetail", method ={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Response getTransOrderDetail(@RequestParam(required = true) String memberId,
								   @RequestParam(required = true) String orderId,@RequestParam(required = true) String transactionType) throws Exception {
		logBefore(logger, "zw交易数据详情");
		Map<String, Object> map = null;
		try {
			map = wxApiFindShopService.getTransOrderDetail(memberId,orderId,transactionType);
			if(map == null || map.size()==0){
				throw new ApplicationException(Rescode.FAIL,"未查询到记录");
			}
			return Response.getSuccess(map);
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			return Response.getError("服务器异常");
		}
	}

    /**
     * 查询商户信息
     * @param businessCode
     * @param fyMerchantId
     * @param memberId
     * @return
     * @throws Exception
     */
	@RequestMapping(value = "/findMerchantName", method = {RequestMethod.GET,RequestMethod.POST} )
	@ResponseBody
	public Response actualMoney(String businessCode,String fyMerchantId,Integer memberId) throws Exception{
		logBefore(logger, "实际付款金额");
		HashMap<String, String> resultMap = new HashMap<String, String>();
		resultMap.put("台卡编号", businessCode);
		resultMap.put("台卡商户号", fyMerchantId);
		resultMap.put("会员编码", memberId+"");
		String nullParam=Response.checkNull(resultMap);
		if (null != nullParam) {
			return Response.getError(nullParam+"不能为空");
		}
		try {
			Response response=appPayService.findMerchantName(businessCode, fyMerchantId, memberId);
			return response;
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			return Response.getError("服务器异常");
		}
	}
	
	
	
	 /**
     * 查询商户信息
     * @param
     * @param
     * @param memberId
     * @return
     * @throws Exception
     */
	@RequestMapping(value = "/findMerchantNameInfo", method = {RequestMethod.GET,RequestMethod.POST} )
	@ResponseBody
	public Response actualMoneyInfo(String deskcardId,String deskcardCode,Integer memberId) throws Exception{
		logBefore(logger, "实际付款金额");
		HashMap<String, String> resultMap = new HashMap<String, String>();
		resultMap.put("台卡编号", deskcardCode);
		resultMap.put("台卡记录ID", deskcardId);  
		resultMap.put("会员编码", memberId+"");
		String nullParam=Response.checkNull(resultMap);
		if (null != nullParam) {
			return Response.getError(nullParam+"不能为空");
		}
		try {
			Response response=appPayService.findMerchantNameInfo(deskcardId, deskcardCode, memberId);
			return response;
		} catch (ApplicationException ae) {
			logger.error(ae);
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			return Response.getError("服务器异常");
		}
	}
	
	
	
	/**
	 * 钱包台卡交易
	 * @param.
	 * @return
	 */
	@RequestMapping(value = "tkWalletPay")
	@ResponseBody
	public  Response tkWalletPay(HttpServletRequest request,Integer tranAmt,Integer memberId,String deskcardId,String deskcardCode,
			Integer actualTranAmt,Integer nooffertranAmt,String couponUserId,String payPwd) throws Exception{
		   logBefore(logger, "钱包台卡交易");
	       HashMap<String, String> map = new HashMap<String, String>();
	        map.put("支付金额", tranAmt+"");
	        map.put("台卡编号", deskcardCode);
	        map.put("台卡记录ID", deskcardId);      
	        map.put("支付密码", payPwd);
			String nullParam=Response.checkNull(map);  
			if (null != nullParam) {
				return Response.getError(nullParam+"不能为空");
			}
			if(Tools.notEmpty(couponUserId)&&actualTranAmt==null){ 
				return Response.getError("实付金额不能为空");
			}
			if(tranAmt<=0){ 
				return Response.getError("请输入正确的消费金额");
			}
			String orgOrderNum=Const.APP_CONSUME+UtilFun.createOrderNum();
		try {
			Response resultMap=appPayService.updateTkWalletPay(orgOrderNum,memberId, deskcardId, deskcardCode, tranAmt, actualTranAmt, nooffertranAmt,payPwd);
			try {
				wxApiWalletServiceService.finishBuySendMessage(orgOrderNum,"商品购买");
			} catch (Exception e) {
				logBefore(logger, "通知发送异常");
			}
			//异步调用分润
			 try {
				 TradeOffline record=(TradeOffline) resultMap.getData_extend();
				 if(record!=null){
					 wxApiWalletServiceService.updateYcgOrderState(orgOrderNum,record.getTransOrderNo(),"1",null); 
					 memberService.insertMemberTradeDataAsyn(record.getPayerId(),record.getRealAmount(),record.getBonusValue()); 
					 profitStatisService.saveOneOrderProfitCalculate(record.getId());
				 }
			} catch (Exception e) {
						logBefore(logger, "----------分润交易异常-----");
			}
			return resultMap;
		}  catch (ApplicationException ae) {
			logger.error(ae);
			ae.printStackTrace();
			return Response.getError(ae.errMsg);
		}
		catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			return Response.getError("服务器异常");
		}
	}

	/*下面这些接口除了云流使用 商博士2.0也会使用*/

	/*
	* 获取首页商品
	* */
	@RequestMapping(value = "/getFirstGoods")
	@ResponseBody
	public Response getFirstGoods(@RequestParam("memberId") String memberId) {
		List<Map<String, Object>> responseInfo = mallGoodService.listFirstGoods(memberId);
		return Response.getSuccess(responseInfo);
	}
	
	
	/*
	* 获取首页商品
	* */
	@RequestMapping(value = "/listHomeGoods")
	@ResponseBody
	public Response listHomeGoods(@RequestParam("memberId") String memberId) {
		List<Map<String, Object>> responseInfo = mallGoodService.listHomeGoods(memberId);
		return Response.getSuccess(responseInfo);
	}

	/*
	* 获取商品列表
	* */
	@RequestMapping(value = "/getGoods")
	@ResponseBody
	public Response getGoods(@RequestParam("memberId") String memberId, @RequestParam("page") String page, String key, String categroyId) {
		List<Map<String, Object>> responseInfo = mallGoodService.listGoods(memberId, page, key, categroyId);
		return Response.getSuccess(responseInfo);
	}

	/*
	* 提交购物车
	* */
	@RequestMapping(value = "/submitCart")
	@ResponseBody
	public Response submitCart(@RequestParam("memberId") String memberId, @RequestParam("goodsIds") String goodsIds,@RequestParam("addressId") String addressId) {
		String[] goodIdsStr = goodsIds.split(",");
		List<Long> goodIds = new ArrayList<Long>();
		for(int i = 0; i < goodIdsStr.length; i++) {
			goodIds.add(Long.parseLong(goodIdsStr[i]));
		}

		return mallGoodService.addSubmitCart(memberId, goodIds, addressId);
	}

	/*
	* 直接购买
	* */
	@RequestMapping(value = "/directBuy")
	@ResponseBody
	public Response directBuy(@RequestParam("memberId") String memberId, @RequestParam("goodsId") String goodsId, @RequestParam String goodNum) {
		if(Tools.isEmpty(memberId) || Tools.isEmpty(goodsId) || Tools.isEmpty(goodNum)) {
			return Response.getError("缺少参数");
		}
		return mallGoodService.addDirectBuy(memberId, goodsId, goodNum);
	}

	/*
	* 获取订单列表
	* */
	@RequestMapping(value = "/goodsOrders")
	@ResponseBody
	public Response goodsOrders(@RequestParam("memberId") String memberId, @RequestParam("page") String page, String status) {
		List<OrderGood> orderGoodList = mallGoodService.goodsOrders(memberId, page, status);
		return Response.getSuccess(orderGoodList);
	}

	/*
	* 获取订单详情
	* */
	@RequestMapping(value = "/getGoodsOrder")
	@ResponseBody
	public Response getGoodsOrder(@RequestParam("memberId") String memberId, @RequestParam("id") String id) {
		Long memberId1 = Long.parseLong(memberId);
		Long orderId = Long.parseLong(id);

		OrderGood orderGood = mallGoodService.getGoodsOrder(memberId1, orderId);
		return Response.getSuccess(orderGood);
	}

	/*
	* 获取商品详情
	* */
	@RequestMapping(value = "/getGoodsItem")
	@ResponseBody
	public Response getGoodsItem(@RequestParam("memberId") String memberId, @RequestParam("goodsId") String goodsId) {
		Long memberId1 = Long.parseLong(memberId);
		Long goodsId1 = Long.parseLong(goodsId);

		Map<String, Object> goodInfo = mallGoodService.getGoodsItem(goodsId1);

		return Response.getSuccess(goodInfo);
	}

	/*
	* 订单取消
	* */
	@RequestMapping(value = "/orderCancel")
	@ResponseBody
	public Response orderCancel(@RequestParam String memberId, @RequestParam String orderId) {
		if(Tools.isEmpty(memberId) || Tools.isEmpty(orderId)) {
			return Response.getError("缺少参数");
		}

		Long memberId1 = Long.parseLong(memberId);
		Long orderId1 = Long.parseLong(orderId);

		return mallGoodService.saveOrderCancel(memberId1, orderId1,ROOT_HOME_URL);
	}

	/*
	* 订单删除
	* */
	@RequestMapping(value = "/orderDel")
	@ResponseBody
	public Response orderDel(@RequestParam String memberId, @RequestParam String orderId) {
		if(Tools.isEmpty(memberId) || Tools.isEmpty(orderId)) {
			return Response.getError("缺少参数");
		}

		Long memberId1 = Long.parseLong(memberId);
		Long orderId1 = Long.parseLong(orderId);

		return mallGoodService.saveOrderDel(memberId1, orderId1);
	}

	/*
	* 交易记录列表
	* */
	@RequestMapping(value = "/tradeList")
	@ResponseBody
	public Response tradeList(@RequestParam String memberId, @RequestParam String page, String transactionType) {
		if(Tools.isEmpty(memberId) || Tools.isEmpty(page)) {
			return Response.getError("缺少参数");
		}

		Long memberId1 = Long.parseLong(memberId);
		Integer page1 = Integer.parseInt(page);
		Byte  transactionType1 = transactionType == null ? null : (byte)Integer.parseInt(transactionType);

		return tradeService.ysTradeList(memberId1, page1, transactionType1);
	}

	/*
	* 门店消费订单列表
	* */
	@RequestMapping("/ShopSaleList")
	@ResponseBody
	public Response shopSaleList(@RequestParam Long memberId, @RequestParam Integer pageNo,
								 @RequestParam Integer pageSize, String type) {
		Integer status = null;
		if(type != null) {
			status = Integer.parseInt(type);
		}

		return wxApiMemberService.shopSaleList(memberId, pageNo, pageSize, status);
	}

	/*
	* 门店消费订单详情
	* */
	@RequestMapping("/shopSaleOrderDetail")
	@ResponseBody
	public Response shopSaleOrderDetail(@RequestParam Long memberId, @RequestParam Long shopId,
										@RequestParam String orderId, String user_longitude, String user_latitude) {
		try {
			return wxApiMemberService.shopSaleOrderDetail(memberId, shopId, orderId, user_latitude, user_longitude);
		} catch (Exception e) {
			e.printStackTrace();
			return Response.getError("服务器处理错误");
		}
	}

	//MultipartFile img1, MultipartFile img2, MultipartFile img3, MultipartFile img4, MultipartFile img5
	/*
	* 门店消费订单评价
	* */
	@RequestMapping("/ShopSaleOrderEvaluate")
	@ResponseBody
	public Response shopSaleOrderEvaluate(@RequestParam Long memberId, @RequestParam Long shopId, @RequestParam String orderId,
										  @RequestParam String evaluateContent, @RequestParam Integer evaluateSorce, @RequestParam Boolean isAnonymous, Integer transAmt,
										  HttpServletRequest request) {
		String path = "/ebos/yunliuapp/comment/";

		String picUrls = "";

		MultipartFile img1 = null, img2 = null , img3 = null , img4 = null, img5 = null;
		CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(request.getSession().getServletContext());
		if(multipartResolver.isMultipart(request)) {
			MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
			img1 = multipartRequest.getFileMap().get("img1");
			img2 = multipartRequest.getFileMap().get("img2");
			img3 = multipartRequest.getFileMap().get("img3");
			img4 = multipartRequest.getFileMap().get("img4");
			img5 = multipartRequest.getFileMap().get("img5");
		}

		if(img1 != null) {
			String result = fileUpload.upload(img1, path);
			if(!result.equals("failed")) {
				picUrls += result + ",";
			}
		}
		if(img2 != null) {
			String result = fileUpload.upload(img2, path);
			if(!result.equals("failed")) {
				picUrls += result + ",";
			}
		}
		if(img3 != null) {
			String result = fileUpload.upload(img3, path);
			if(!result.equals("failed")) {
				picUrls += result + ",";
			}
		}
		if(img4 != null) {
			String result = fileUpload.upload(img4, path);
			if(!result.equals("failed")) {
				picUrls += result + ",";
			}
		}
		if(img5 != null) {
			String result = fileUpload.upload(img5, path);
			if(!result.equals("failed")) {
				picUrls += result + ",";
			}
		}

		if(!picUrls.equals("")) {
			picUrls = picUrls.substring(0, picUrls.length() - 1);
		}

		return wxApiMemberService.saveShopSaleOrderEvaluate(memberId, shopId, orderId, evaluateContent, evaluateSorce, isAnonymous, picUrls);
	}
}
